import {
  IsNotEmpty,
  IsString,
  IsOptional,
  IsInt,
  Min,
  Max,
  IsUrl,
  MaxLength,
  IsArray,
  ArrayMinSize,
  ValidateNested
} from 'class-validator';
import { BaseRequestListDto } from './baseRequestList.dto';
import { Expose, Type } from 'class-transformer';

export class CreateArticleDto {
  @IsNotEmpty({ message: '标题不能为空' })
  @IsString({ message: '标题必须是字符串' })
  @MaxLength(100, { message: '标题最长100个字符' })
  title!: string;

  @IsNotEmpty({ message: '内容不能为空' })
  @IsString({ message: '内容必须是字符串' })
  content!: string;


  @IsOptional()
  coverImage?: string;


  @IsOptional()
  @IsInt({ message: '状态必须是整数' })
  @Min(0, { message: '状态最小值为0' })
  @Max(1, { message: '状态最大值为1' })
  status?: number = 1;


  userId?: number;

  @IsOptional()
  @IsInt({ message: '分类ID必须是整数' })
  categoryId?: number;

  comment?: string
}


export class UpdateArticleDto {
  @IsNotEmpty({ message: "id不能为空！" })
  id!: number;


  @IsString({ message: '标题必须是字符串' })
  @MaxLength(100, { message: '标题最长100个字符' })
  title!: string;

  @IsNotEmpty({ message: '内容不能为空' })
  @IsString({ message: '内容必须是字符串' })
  content?: string;


  @IsOptional()
  @IsString()
  coverImage?: string;


  @IsOptional()
  @IsInt({ message: '状态必须是整数' })
  @Min(0, { message: '状态最小值为0' })
  @Max(1, { message: '状态最大值为1' })
  status?: number;

  @IsNotEmpty({ message: '作者ID不能为空' })
  @IsInt({ message: '作者ID必须是整数' })
  userId?: number;

  @IsOptional()
  @IsInt({ message: '分类ID必须是整数' })
  categoryId?: number;

  comment?: string

}

export class QueryArticleDto extends BaseRequestListDto {
  status?: number
  categoryId?: number;
  title?: string;
  comment?: string
}

export class DeleteArticleDto {
  @IsNotEmpty({ message: 'ID列表不能为空' })
  @IsInt({ each: true, message: '每个ID必须是整数' })
  ids!: number[];
}
export class SelectOneArticleDto {
  @IsNotEmpty({ message: 'ID列表不能为空' })
  id!: number;
}


export class ArticleResponseDto {
  @Expose()
  id?: number;

  @Expose()
  title?: string;

  @Expose()
  excerpt?: string; // 从content截取

  @Expose()
  coverImage?: string | null;

  @Expose()
  status?: number;

  @Expose()
  viewCount?: number;

  @Expose()
  userId?: number;

  @Expose()
  categoryId?: number | null;

  @Expose()
  createdAt?: Date;

  @Expose()
  updatedAt?: Date;

  @Expose()
  comment?: string

}
